refactor: use dependency injection for InsightsBookingService#22790
refactor: use dependency injection for InsightsBookingService#22790eunjae-lee merged 10 commits intomainfrom
Conversation
- Add DI tokens for InsightsBookingService and module - Rename InsightsBookingService to InsightsBookingBaseService - Create InsightsBookingService DI interface with create method - Add DI module and container for InsightsBookingService - Update tRPC router to use getInsightsBookingService DI container - Update test file to use InsightsBookingBaseService - Update documentation to reflect new DI pattern Follows the same dependency injection pattern established for InsightsRoutingService in PR #22677 Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
WalkthroughThis change introduces a dependency injection (DI) architecture for the insights booking service. A new DI container and module are added for the insights booking service, with corresponding DI tokens. The service instantiation in the tRPC router is refactored to use the DI container via a new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Complexity label: Moderate Possibly related PRs
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
…ally - Keep createInsightsBookingService helper function for cleaner API - Use getInsightsBookingService DI container internally - Maintain same function signature and behavior - All existing calls continue to work unchanged Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
- Rename insightsBookingBase.ts to InsightsBookingBaseService.ts - Rename insightsBookingDI.ts to InsightsBookingDIService.ts - Update all import statements to use new file names - Maintain existing handler functionality using createInsightsBookingService(ctx, input) Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (07/29/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add ready-for-e2e label" took an action on this PR • (08/04/25)1 label was added to this PR based on Keith Williams's automation. |
hbjORbj
left a comment
There was a problem hiding this comment.
Love it :D You have a merge conflict though. Feel free to ping me once more for approval
E2E results are ready! |
refactor: use dependency injection for InsightsBookingService
Summary
This PR refactors
InsightsBookingServiceto use dependency injection, following the exact same pattern established forInsightsRoutingServicein PR #22677. The changes include:InsightsBookingService→InsightsBookingBaseServiceInsightsBookingServicewithcreate()method@evyweb/ioctopuscreateInsightsBookingServicehelper that now usesgetInsightsBookingService()DI container internallycreateInsightsBookingService(ctx, input)The refactoring maintains the same public API while enabling dependency injection for better testability and modularity. All existing functionality should be preserved.
Review & Testing Checklist for Human
InsightsRoutingServiceDI pattern from PR refactor: use dependency injection for InsightsRoutingService #22677 (same tokens, module structure, container setup)bookingKPIStats,eventsByHourStats,popularEvents,memberStats, etc. all usecreateInsightsBookingService(ctx, input)correctlyRecommended test plan: Navigate to the insights dashboard and verify that all charts, stats, and data exports load correctly with the same data as before the refactoring. Pay special attention to date filtering and team/user scoping functionality.
Diagram
%%{ init : { "theme" : "default" }}%% graph TD subgraph "tRPC Router" Router["packages/features/insights/<br/>server/trpc-router.ts"]:::major-edit end subgraph "Service Layer" OldService["packages/lib/server/service/<br/>insightsBooking.ts<br/>(DELETED)"]:::major-edit BaseService["packages/lib/server/service/<br/>InsightsBookingBaseService.ts<br/>(renamed from above)"]:::major-edit DIService["packages/lib/server/service/<br/>InsightsBookingDIService.ts<br/>(NEW)"]:::major-edit end subgraph "DI Infrastructure" Tokens["packages/lib/di/tokens.ts"]:::minor-edit Module["packages/lib/di/modules/<br/>insights-booking.ts<br/>(NEW)"]:::major-edit Container["packages/lib/di/containers/<br/>insights-booking.ts<br/>(NEW)"]:::major-edit end subgraph "Tests & Docs" Tests["packages/lib/server/service/<br/>__tests__/insightsBooking.integration-test.ts"]:::minor-edit Docs["packages/features/insights/<br/>HOW_TO_ADD_BOOKING_CHARTS.md"]:::minor-edit end Router -->|"uses createInsightsBookingService()"| Container Container -->|"creates"| DIService DIService -->|"instantiates"| BaseService Module -->|"binds"| DIService Container -->|"loads"| Module Tests -->|"imports"| BaseService subgraph Legend L1["Major Edit"]:::major-edit L2["Minor Edit"]:::minor-edit L3["Context/No Edit"]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
InsightsRoutingServicecreateInsightsBookingServicehelper function was restored per feedback and now usesgetInsightsBookingServiceinternallycreateInsightsBookingService(ctx, input)lockedTimeZoneerrors in other files, which were explicitly skipped per user instructionLink to Devin run: https://app.devin.ai/sessions/75ca69a009b8483a9b6dd4a1e472f66f
Requested by: @eunjae-lee